﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RestaurateurConsole
{
    public partial class AddXAction : Form
    {
        private bool cancelled = false;
        private XAction xaction = new XAction();
        public AddXAction()
        {
            InitializeComponent();
        }

        private void AddXAction_Load(object sender, EventArgs e)
        {
            dateTimePicker1.Value = DateTime.Now;
            textBox1.Text = (0).ToString(); ;
            textBox4.Text = (0).ToString();
            listBox1.SelectedIndex = 0;
            listBox2.SelectedIndex = 0;
        }

        private void Okay()
        {
            try
            {
                xaction.TransactionDate = dateTimePicker1.Value;
                xaction.DepositAmount = Decimal.Parse(textBox1.Text);
                xaction.WithdrawAmount = Decimal.Parse(textBox4.Text);
            }
            catch
            {
                MessageBox.Show("Please enter only numbers in amount fields.");
                return;
            }
            xaction.DepositType = (depositType)listBox1.SelectedIndex;
            xaction.WithdrawType = (withdrawType)listBox2.SelectedIndex;
            xaction.DepositComment = textBox2.Text;
            xaction.WithdrawComment = textBox3.Text;
            xaction.PayerName = textBox6.Text;
            xaction.PayeeName = textBox8.Text;
            this.Close();
        }

        private void Cancel()
        {
            cancelled = true;
            this.Close();
        }

        public Boolean IsCancelled { get { return cancelled; } }
        public XAction Transaction { get { return xaction; } }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            listBox1.SelectedIndex = 2;
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            return;
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            listBox2.SelectedIndex = 1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Okay();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Cancel();
        }

    }
}
